package com.wecan.components.oss.config;

import com.wecan.base.constants.PropertyConstants;
import com.wecan.components.oss.controller.OSSController;
import com.wecan.components.oss.properties.OSSProperties;
import com.wecan.components.oss.service.OSSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Author liuzhihao
 * @Date 2022.01.15
 * @Version 1.0.0
 * @Description oss配置
 */
@Configuration
@EnableConfigurationProperties(OSSProperties.class)
@ConditionalOnProperty(name = PropertyConstants.APP_OSS_ACCESS_KEY)
@Slf4j
public class OSSConfig {

    @PostConstruct
    public void postConstruct() {
        log.info("[APP] |- 初始化OSS文件服务");
    }

    @Bean
    public OSSService ossService() {
        return new OSSService();
    }

    @Bean
    @ConditionalOnBean(OSSService.class)
    @ConditionalOnProperty(name = PropertyConstants.APP_OSS_OPEN_SERVLET, havingValue = "true")
    public OSSController ossController() {
        log.info("[APP] |- 初始化ossweb层服务");
        return new OSSController();
    }
}
